package com.zdb.demo.design.pattern.creational.singleton;

public class StaticInnerClassSingleton {

    private static class Inner {
        private static StaticInnerClassSingleton innerClassSingleton;

        static {
            innerClassSingleton = new StaticInnerClassSingleton();
        }
    }

    /**
     * 因为类加载时会有锁，在1,2,3执行完成后才会释放锁，所以不用担心指令重排的问题
     * @return
     */
    public static StaticInnerClassSingleton getInstance() {
        return Inner.innerClassSingleton;
    }

}
